package com.pmsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.News;
import com.pmsystem.service.NewsService;

/**
 * 
* <p>Title: NewsController</p>  
* <p>Description:新闻政务发布的控制器 </p>  
* @author 树昌  
* @date 2019年1月24日
 */
@Controller
@RequestMapping("news/")
public class NewsController {

	@Autowired
	NewsService newsService;
	
	/**
	 * 
	 * <p>Title: writeNews</p>  
	 * <p>Description:编写新闻草稿的控制器 </p>  
	 * @author 树昌
	 * @param news
	 * @return 跳转到编辑者的页面
	 */
	@RequestMapping(value="write",method=RequestMethod.POST)
	public String writeNews(News news) {
		newsService.writeNews(news);
		return "editor";
	}
	
	/**
	 * 
	 * <p>Title: showEditorNews</p>  
	 * <p>Description:编辑者查看新闻视图的控制器 </p>  
	 * @author 树昌
	 * @param keyword 搜索关键词
	 * @param startRow	页码
	 * @param pageSize	一页显示的记录条数
	 * @return 不做跳转
	 */
	@RequestMapping(value="editor",method=RequestMethod.POST)
	@ResponseBody
	public List<News> showEditorNews(String keyword, Integer startRow, Integer pageSize){
		
		return  newsService.showEditorNews(keyword, startRow, pageSize);
	}
	
	/**
	 * 
	 * <p>Title: releaseNews</p>  
	 * <p>Description:发布新闻 </p>  
	 * @author 树昌
	 * @param news
	 * @return	跳转到阅读者页面
	 */
	@RequestMapping(value="releasenews",method=RequestMethod.POST)
	public String releaseNews(News news) {
		
		boolean row = newsService.releaseNews(news);
		if(row) {
			return "reader";
		}else {
			return "error";
		}
	}
	
	
	
	/**
	 * 
	 * <p>Title: showReaderNews</p>  
	 * <p>Description: </p>  
	 * @author 树昌
	 * @param keyword	搜索关键词
	 * @param startRow	页码
	 * @param pageSize	一页显示的记录条数
	 * @return 不做跳转
	 */
	@RequestMapping(value="reader",method=RequestMethod.POST)
	@ResponseBody
	public List<News> showReaderNews(String keyword, Integer startRow, Integer pageSize){
		
		return newsService.showReaderNews(keyword, startRow, pageSize);
	}
	
	
	/**
	 * 
	 * <p>Title: deleteNews</p>  
	 * <p>Description:删除新闻 </p>  
	 * @author 树昌
	 * @param news
	 * @return 不做跳转
	 */
	@RequestMapping(value="deletenews",method=RequestMethod.POST)
	public String deleteNews(News news) {
		
		boolean row = newsService.deleteNews(news);
		if(row==true) {
			return null;
		}else {
			return "error";
		}
	}
	
	/**
	 * 
	 * <p>Title: updateNews</p>  
	 * <p>Description:修改一条新闻的控制器 </p>  
	 * @author 树昌
	 * @param news
	 * @return 跳转到编辑者页面
	 */
	@RequestMapping(value="updatenews",method=RequestMethod.POST)
	public String updateNews(News news) {
		
		boolean row = newsService.updateNews(news);
		if(row) {
			return "news/editor";
		}else {
			return "error";
		}
	}
	
}
